package com.buba.controller;


import com.buba.service.PlaceForStorageService;
import common.R;
import entity.device.PlaceForStorage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.buba.mapper.PlaceForStorageMapper;
import com.buba.service.PlaceForStorageService;
import entity.device.PlaceForStorage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import java.util.List;

/**
 * <p>
 * 存放位置 前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-05-18
 */
@RestController
@RequestMapping("/place-for-storage")
public class PlaceForStorageController {
    @Autowired
    private PlaceForStorageService placeForStorageService;

    /* *
     * @Author: beisheng
     * @Descriprion: 查询所有设备存放位置
     * @Date: 2023/5/22 14:27
     * @Return: common.R
     * @Param: []
     */

    @GetMapping("/selPlace")
    public R selPlace(){
        List<PlaceForStorage>  placeForStorages = placeForStorageService.selPlace();
        return R.success(placeForStorages);
    }
    /**
     * 存放位置列表查询
     *
     * @return
     */
    @GetMapping("selAllStorage")
    public R queryAll(String locationName) {
        return R.success(placeForStorageService.queryAll(locationName));
    }

    /**
     * @return common.R
     * @Author atlong
     * @Description 查询已开启的设备位置信息
     * @Date 2023/6/1 20:02
     * @Param []
     **/
    @GetMapping("queryAll")
    public R selAllStorage() {
        return R.success(placeForStorageService.selAllStorage());
    }

    /**
     * 新增位置
     *
     * @param placeForStorage
     * @return
     */
    @PostMapping("insetStorage")
    public R insertAll(@RequestBody PlaceForStorage placeForStorage) {
        boolean b = placeForStorageService.insetStorage(placeForStorage);
        return b ? R.success() : R.error();
    }

    /**
     * 编辑列表
     *
     * @param placeForStorage
     * @return
     */
    @PostMapping("updateStorage")
    public R updateStorage(@RequestBody PlaceForStorage placeForStorage) {
        boolean b = placeForStorageService.updateStorage(placeForStorage);
        return b ? R.success() : R.error();
    }

    /**
     * 逻辑删除
     *
     * @param idArray
     * @return
     */

    @PostMapping("deletePlaceById")
    public R deleteAll(@RequestBody List<Integer> idArray) {
        boolean b = placeForStorageService.deleteAll(idArray);
        return b ? R.success() : R.error();
    }

    /**
     * 批量启用
     *
     * @param idArray
     * @return
     */
    @PostMapping("startUsing")
    public R startUsing(@RequestBody Integer[] idArray) {
        boolean b = placeForStorageService.startUsing(idArray);
        return b ? R.success() : R.error();
    }

    /**
     * 批量停用
     *
     * @param idArray
     * @return
     */
    @PostMapping("outService")
    public R outService(@RequestBody Integer[] idArray) {
        boolean b = placeForStorageService.outService(idArray);
        return b ? R.success() : R.error();
    }
}

